package com.yihengyi.demo.controller;

import com.yihengyi.demo.bean.User;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * test controller.
 *
 * @author liucheng
 * @since 0.1 2021-01-20 10:24 下午
 **/
@CrossOrigin
@RestController
public class TestController {
    @GetMapping("/test1")
    @ResponseStatus(HttpStatus.BAD_GATEWAY)
    public void test1() {
//        return "{\"key\": 1}";
    }

    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User(1L, "张三"));
        users.add(new User(2L, "李四"));
        users.add(new User(3L, "张三"));
        users.add(new User(4L, "王五"));
        users.add(new User(5L, "张三"));
        users.add(new User(6L, "李四"));
        users.add(new User(7L, "张三"));

        Map<String, Long> collect = users.stream().collect(Collectors.groupingBy(User::getName, Collectors.counting()));
        System.out.println(collect);
        System.out.println(collect.get("张三"));
    }
}
